package collection;

import javax.swing.plaf.IconUIResource;
import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo3 {
    public static void main(String[] args) {
        Collection con = new ArrayList();
        Point p = new Point(1,2);
        con.add(p);//将p的地址装入了ArrayList
        p.setX(100);//p的x改为了200，ArrayList里指向p对象的引用没有变化，所以集合输出也会跟着变化
        Collection collection = new ArrayList();
        collection.add(1);
        collection.add(2);
        collection.add(3);
        collection.addAll(con);
        System.out.println(collection);
        System.out.println(con);
        System.out.println(collection.contains(con));
        Collection collection1 = new ArrayList();
        collection1.add(1);
        collection1.add(100);
       /* collection.retainAll(collection1);//保留共有的
        System.out.println("collection:"+collection);
        System.out.println("collection1:"+collection1);
        */
        collection.removeAll(collection1);//删除共有的
        System.out.println("collection:"+collection);
        System.out.println("collection1:"+collection1);
    }
}
